package com.neutech.controller;

import com.google.gson.Gson;
import com.neutech.entity.Business;
import com.neutech.service.BusinessService;
import com.neutech.service.impl.BusinessServiceImpl;
import com.neutech.vo.ResultVO;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(urlPatterns = "/business/getById")

public class BusinessByIdServlet extends HttpServlet {
    private BusinessService businessService = new BusinessServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

            String id = req.getParameter("id");

            PrintWriter out =resp.getWriter();
            Gson gson = new Gson();

            if (id==null){
                out.print(gson.toJson(ResultVO.error(1001,"id不能为空")));
                out.close();
                return;
            }
            out.println(gson.toJson(businessService.getById(Integer.parseInt(id))));

            out.close();

    }
}
